package com.careercup.question.id14949008;

public class Solution {
	private static int atoi( String str)
	{
		char[] c1= str.toCharArray();
		int len = str.length();
		int i = 0, num = 0;
		boolean isneg = false;

		if (len == 0)
			System.out.println(" empty string");

		if (c1[0] == '-') {
			isneg = true;
			i = 1;
		}

		while( i < len) {
			num = num * 10;
			num = num + (c1[i] - '0');
			i++;
		}

		if (isneg == true)
			return( num * -1);
		else
			return num;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(atoi("98765"));
	}
}
